package com.itheima.reggie.config;

import com.itheima.reggie.interceptor.LoginCheckInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
//@Configuration
public class WebMvcConfig2 implements WebMvcConfigurer {
    @Autowired
    private LoginCheckInterceptor loginCheckInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        log.info("开始进行静态资源映射...");
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(loginCheckInterceptor)
                .addPathPatterns("/**")
                //排除不拦截的资源
                .excludePathPatterns("/employee/login")
                .excludePathPatterns("/employee/logout")
                .excludePathPatterns("/backend/**")
                .excludePathPatterns( "/front/**")
                .excludePathPatterns( "/common/**")
                .excludePathPatterns( "/user/sendMsg")
                .excludePathPatterns( "/user/login");
    }
}
